package edu.gatech.mobile.scene.ui;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import edu.gatech.mobile.scene.R;
import edu.gatech.mobile.scene.image.util.MatUtil;
import edu.gatech.mobile.scene.ui.camera.CaptureActivity;
import edu.gatech.mobile.scene.ui.manage.ManageImageActivity;

public class DataLoadingActivity extends Activity implements OnClickListener{
	
	private static final String TAG = DataLoadingActivity.class.getSimpleName();
	
	private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
		@Override
		public void onManagerConnected(int status) {
			switch (status) {
			case LoaderCallbackInterface.SUCCESS:
				Log.i(TAG, "OpenCV loaded successfully");
				initApplicatoniContext();
				break;
			default:
				super.onManagerConnected(status);
				break;
			}
		}
	};
	
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this,
				mOpenCVCallBack)) {
			Log.e(TAG, "Cannot connect to OpenCV Manager");
		}
	}
	
	private void initApplicatoniContext() {
		if(MatUtil.initializeApplicationContext(this)){
			Toast.makeText(this, "Data loaded", Toast.LENGTH_LONG).show();
			setContentView(R.layout.activity_main);
			((Button)findViewById(R.id.new_image)).setOnClickListener(this);
			((Button)findViewById(R.id.manage_image)).setOnClickListener(this);
		}
	}

	@Override
	public void onClick(View v) {
		Intent i = null;
		switch (v.getId()) {
		case R.id.new_image:
			i = new Intent(this, CaptureActivity.class);
			startActivity(i);
			break;
		case R.id.manage_image:
			i = new Intent(this, ManageImageActivity.class);
			startActivity(i);
			break;
		default:
			break;
		}
		
	}
}
